package com.ljm.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljm.domain.Book;
import com.sun.source.tree.LambdaExpressionTree;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class BookDaoTestCase {

    @Autowired
    private BookDao bookDao;

    @Test
    void testGetById(){
//        System.out.println(bookDao.getById(1));
        System.out.println(bookDao.selectById(2));
    }

    @Test
    void testSave(){
        Book book = new Book();
        book.setName("测试");
        book.setType("测试");
        book.setDescription("测试");
        bookDao.insert(book);
    }

    @Test
    void testUpdate(){
        Book book = new Book();
        book.setId(112);
        book.setName("测试123");
        book.setType("测试");
        book.setDescription("测试");
        bookDao.updateById(book);
    }

    @Test
    void testDelete(){
        bookDao.deleteById(111);
    }

    @Test
    void testGetPage(){
        IPage page = new Page(2,3);
        bookDao.selectPage(page,null);
    }

    @Test
    /*按条件查询*/
    void testGetBy(){
        QueryWrapper<Book> qw = new QueryWrapper<>();
        qw.like("name","高数");
        //eq lg
        bookDao.selectList(qw);
    }
    @Test
    void testGetBy2(){
        String name=null;
        LambdaQueryWrapper<Book> qw = new LambdaQueryWrapper<>();
//        qw.like(Book::getName,"高数");
        qw.like(name!=null,Book::getName,name);
        bookDao.selectList(qw);
    }

}






























